<?php require_once('Connections/sepolwan_connect.php'); 
require 'fblogin/src/config.php';
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=md5($_POST['password']);
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = $_GET['url'];
  $MM_redirectLoginFailed = "?stat=gagal";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
  
  $LoginRS__query=sprintf("SELECT email, password FROM memberdb WHERE email=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $sepolwan_connect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
if ($_SESSION['MM_Username']<>'') {
	header("Location: index.php" );
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Login</title>
<link href="gaya/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center" style="color:#F00"><?php if ($_GET['stat']==gagal) { ?>Kombinasi Email dan Password Anda Salah ! <?php } ?>
<?php if ($_GET['key']>'') { ?>Aktifasi akun berhasil, silahkan login ! <?php } ?></p>
<table width="300" style="border:1px #ccc solid" align="center" cellpadding="20" cellspacing="0">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><img src="images/logo2.png" width="188" height="57" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
      <label for="username"></label>
      <input name="username" type="text" id="username" placeholder="Email .. "  style="margin-bottom:15px; width:245px" />
      <label for="password"></label>
      <input name="password" type="password" id="password" placeholder="Password .. " style="margin-bottom:15px; width:245px" />
      <input type="submit" name="submit" id="submit" value="Sign In" style="width:260px; font-weight:bold; height:40px" />
    </form></td>
  </tr>
</table><br />
<div align="center"><?php echo $content = '<a href="https://www.facebook.com/dialog/oauth?client_id='.$config['App_ID'].'&redirect_uri='.$config['callback_url'].'&scope=email,user_likes,publish_stream"><img src="fblogin/images/login-button.png" alt="Sign in with Facebook"/></a>'; ?></div>
</body>
</html>